package cn.tedu.scalaimplicit

/**
 * @author Amos
 * @date 2022/5/18
 */

object ImplicitTest {

  //被implicit修饰的值，叫做隐式值
  implicit val name = 10
  implicit val name1 = "赵敏"

  // 通过implicit修饰的参数，叫做隐式参数,匹配隐式值的时候，找的是值类型，不是名称
  def sayHi(implicit name:String): Unit ={
    println(s"hello,$name")
  }

  // 如果有多个参数的时候，需要通过函数柯里化指定隐式参数
  def sayHello(name:String,address:String)(implicit age:Int): Unit ={
    println(s"hello,$name,今年$age,来自于$address")
  }

  def sayHello1(address:String)(implicit age:Int, name:String): Unit ={
    println(s"hello,$name,今年$age,来自于$address")
  }

  def main(args: Array[String]): Unit = {
    sayHi("张同学") // hello,张同学
    sayHi  // hello,张无忌
    sayHello("张无忌","杭州")(20)
    sayHello("金毛狮王","杭州")

    sayHello1("重庆袁家岗")
  }

}
